home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 117
/
FreelogNo117-OctobreNovembre2013.iso
/
Programmation
/
jedit
/
jedit5.1.0install.exe
/
{app}
/
macros
/
Emacs
/
Emacs_Transpose_Lines.bsh
< prev
next >
Wrap
Text File
|
2013-07-28
|
1KB
|
46 lines
/**
* Transpose line at caret with previous line, and move caret to next line.
* Emulates Emacs "transpose-lines" command (without prefix argument support).
*/
source (MiscUtilities.constructPath(dirname(scriptPath), "EmacsUtil.bsh"));
void emacsTransposeLines()
{
caret = textArea.getCaretPosition();
if ((caret == 0) || atEndOfBuffer())
{
beep();
return;
}
caretLine = textArea.getCaretLine();
lineStart = textArea.getLineStartOffset (caretLine);
lineEnd = textArea.getLineEndOffset (caretLine);
lineIndex = textArea.getLineOfOffset (caretLine);
selection = new Selection.Range (lineStart, lineEnd);
line = textArea.getSelectedText(selection);
// Get the location of the previous line
textArea.goToPrevLine (false);
prevLineCaret = textArea.getCaretLine();
prevLineStart = textArea.getLineStartOffset (prevLineCaret);
// Go back to the original location.
textArea.setCaretPosition (caret);
// Delete the line
textArea.deleteLine();
// Insert it in the new location.
buffer.insert (prevLineStart, line);
}
emacsTransposeLines();